package no.evalanche.io;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.json.JSONException;
import org.json.JSONObject;

import android.net.http.AndroidHttpClient;
import android.util.Log;

public class ResultIO  extends MC_Async {

	public ResultIO(String s) {
		sessionid = s;		
	}

	@Override
	protected JSONObject doInBackground(EntityList ... pams) {
		JSONObject jsonobject = null;
		AndroidHttpClient httpclient = AndroidHttpClient.newInstance("android");
		HttpPost request = new HttpPost(ServiceList.URL.toString());
		request.setHeader("Cookie", "sessionid=" + sessionid);
		try {					
			request.setEntity(new UrlEncodedFormEntity(pams[0]));
			jsonobject = jsonFromEntity(null);	
			httpclient.execute(request);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		httpclient.close();
		return jsonobject;
	}
	
	private JSONObject jsonFromEntity(HttpResponse r) throws IOException {
		JSONObject j = new JSONObject();
		try {
			j.accumulate("result", "OK");
		} catch (JSONException e) {
			e.printStackTrace();
		}
	  return j;
	}

}
